package com.thinkgem.jeesite.common.utils.cxf;


import java.util.Enumeration;

import javax.servlet.ServletContext;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class ContextUtils {

	public static WebApplicationContext getSpringMVCContext() {
		WebApplicationContext rootWac = ContextLoader.getCurrentWebApplicationContext();
		
		//获取servletContext
		System.out.println("获取servletContext");
		ServletContext servletContext = rootWac.getServletContext();
		String[] beanNames = rootWac.getBeanDefinitionNames();
		for(String beanName:beanNames) {
			System.out.println("beanName="+beanName);
		}
	
		//查看servlet中容器列表
		Enumeration<String> sevletNames = servletContext.getAttributeNames();
		while(sevletNames.hasMoreElements()) {
			System.out.println("Servlet:"+sevletNames.nextElement());
		}
		
		WebApplicationContext springmvc = WebApplicationContextUtils.getWebApplicationContext(servletContext, "org.springframework.web.servlet.FrameworkServlet.CONTEXT.SpringMVC");
		return springmvc;
		
	}
}
